<?php require("admin-header.php");

        if(isset($OJ_LANG)){
                require_once("../lang/$OJ_LANG.php");
        }


require_once("../include/set_get_key.php");
if (!(isset($_SESSION['administrator'])
                ||isset($_SESSION['contest_creator'])
                ||isset($_SESSION['problem_editor'])
                )){
        echo "<a href='../loginpage.php'>Please Login First!</a>";
        exit(1);
}
$keyword=$_GET['keyword'];
$keyword=mysql_real_escape_string($keyword);
$sql="SELECT max(`problem_id`) as upid FROM `problem`";
$page_cnt=50;
$result=mysql_query($sql);
echo mysql_error();
$row=mysql_fetch_object($result);
$cnt=intval($row->upid)-1000;
$cnt=intval($cnt/$page_cnt)+(($cnt%$page_cnt)>0?1:0);
if (isset($_GET['page'])){
        $page=intval($_GET['page']);
}else $page=$cnt;
$pstart=1000+$page_cnt*intval($page-1);
$pend=$pstart+$page_cnt;

$sql="select `problem_id`,`title`,`hard`,`in_date`,`defunct`,`class` FROM `problem` where problem_id>=$pstart and problem_id<=$pend order by `problem_id` desc";
//echo $sql;
if($keyword) $sql="select `problem_id`,`title`,`hard`,`in_date`,`defunct`,`class` FROM `problem` where title like '%$keyword%' or source like '%$keyword%'";
$result=mysql_query($sql) or die(mysql_error());
?>

<center>
<table width='80%' class='table table-striped table-condensed'>
<form method=post action=contest_add.php>
<tr><td colspan=7>
<input type=submit class="btn btn-primary" name='problem2contest' value='将选中项添加为比赛'>
<tr><td>题目编号<td>难度<td>标题<td>上传日期

<?php

if(isset($_SESSION['administrator'])||isset($_SESSION['problem_editor'])){
        if(isset($_SESSION['administrator']))   echo "<td>状态<td>删除";
        echo "<td>编辑<td>测试数据</tr>";
}
for (;$row=mysql_fetch_object($result);){
        echo "<tr>";
        echo "<td><input type=checkbox name='pid[]' value='$row->problem_id'>  ".$row->problem_id;
		if($row->class==1)echo "  <span class='label label-success'>Begin</span>";
		if($row->class==2)echo "  <span class='label label-primary'>NOIp</span>";
		echo "<td>".$row->hard;
        echo "<td><a href='../problem.php?id=$row->problem_id'>".$row->title."</a>";
        echo "<td>".$row->in_date;
        if(isset($_SESSION['administrator'])||isset($_SESSION['problem_editor'])){
                if(isset($_SESSION['administrator'])||isset($_SESSION['problem_editor'])){
                        echo "<td><a href=problem_df_change.php?id=$row->problem_id&getkey=".$_SESSION['getkey'].">"
                        .($row->defunct=="N"?"<span>开启</span>":"<span class=red title='click to be available'><font color=red>隐藏</font></span>")."</a><td>";
                        if(isset($_SESSION['administrator'])){
                              ?>
                              <a href=# onclick='javascript:if(confirm("Delete?")) location.href="problem_del.php?id=<?php echo $row->problem_id?>&getkey=<?php echo $_SESSION['getkey']?>";'>
                              删除</a>
                              <?php
                        }
                }
                if(isset($_SESSION['administrator'])||isset($_SESSION["p".$row->problem_id])){
                        echo "<td><a href=problem_edit.php?id=$row->problem_id&getkey=".$_SESSION['getkey'].">编辑</a>";
                        echo "<td><a href=/dataadmin.php?op=home&folder=/home/judge/data/$row->problem_id/>查看测试数据</a>";
                }
        }
        echo "</tr>";
}
echo "<tr><td colspan=7>";
echo "</tr></form>";
echo "</table></center>";
?>
<div>
              <form class="form-inline" role="form" action="problem_list.php" method="GET">

                  <label class="sr-only" for="text">搜索题目</label>
                  <input placeholder="按回车搜索" name="keyword" id="text" class="form-control" />

              </form>
</div>
<center>
<ul class="pagination">
     <?php
	if($page!=1)echo "<li><a href='problemset.php?page=".($page-1)."'>&laquo;</a></li>";
	else echo "<li><a>&laquo;</a></li>";
    for ($i=1;$i<=$cnt;$i++){
		if ($i>1) echo '&nbsp;';
		if ($i==$page)echo "<li  class='active'><a>".$i."</a></li>";
		else echo "<li><a href='problemset.php?page=".$i."'>".$i."</a></li>";
	}
	if($page+1<$view_total_page)echo "<li><a href='problemset.php?page=".($page+1)."'>&raquo;</a></li>";
	else echo "<li><a>&raquo;</a></li>";
    ?>
</ul>
</center>
<?php
require("../oj-footer.php");
?>
